gusucode.com > 耐品图片管理系统 标准版A > 耐品图片管理系统 标准版A/Admin_ClassOrder.asp

    <!--#include file="Admin_ChkPurview.asp"-->
<%
'===============================================================
' 著作权号:中国国家版权局著作权登记号2004SR07385
' 版权所有:深圳市耐品科技开发有限公司 www.naipin.com
' 联系电话:0755-26611119 81234844 81234845
' 联系手机:13316911914
' 联系邮箱:naipin@naipin.com
'===============================================================

sub UpOrder()
	dim ID,sqlOrder,rsOrder,MoveNum,cRootID,tRootID,i,rs,PrevID,NextID
	ID=trim(request("ID"))
	cRootID=Trim(request("cRootID"))
	MoveNum=trim(request("MoveNum"))
	if ID="" then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>参数不足!</li>"
	else
		ID=CLng(ID)
	end if
	if cRootID="" then
		FoundErr=true
		ErrMsg=ErrMsg & "<br><li>错误参数!</li>"
	else
		cRootID=Cint(cRootID)
	end if
	if MoveNum="" then
		FoundErr=true
		ErrMsg=ErrMsg & "<br><li>错误参数!</li>"
	else
		MoveNum=Cint(MoveNum)
		if MoveNum=0 then
			FoundErr=True
			ErrMsg=ErrMsg & "<br><li>请选择要提升的数字!</li>"
		end if
	end if
	if FoundErr=True then
		exit sub
	end if

	'得到本分类的PrevID,NextID
	set rs=conn.execute("select PrevID,NextID From NT_ClassName where ID=" & ID)
	PrevID=rs(0)
	NextID=rs(1)
	rs.close
	set rs=nothing
	'先修改上一分类的NextID和下一分类的PrevID
	if PrevID>0 then
		conn.execute "Update NT_ClassName set NextID=" & NextID & " where ID=" & PrevID
	end if
	if NextID>0 then
		conn.execute "Update NT_ClassName set PrevID=" & PrevID & " where ID=" & NextID
	end if

	dim mrs,MaxRootID
	set mrs=conn.execute("select max(rootid) From NT_ClassName")
	MaxRootID=mrs(0)+1
	'先将当前分类移至最后,包括子分类
	conn.execute("Update NT_ClassName set RootID=" & MaxRootID & " where RootID=" & cRootID)
	
	'然后将位于当前分类以上的分类的RootID依次加一,范围为要提升的数字
	sqlOrder="select * From NT_ClassName where ParentID=0 and RootID<" & cRootID & " order by RootID desc"
	set rsOrder=server.CreateObject("adodb.recordset")
	rsOrder.open sqlOrder,conn,1,3
	if rsOrder.bof and rsOrder.eof then
		exit sub        '如果当前分类已经在最上面,则无需移动
	end if
	i=1
	do while not rsOrder.eof
		tRootID=rsOrder("RootID")       '得到要提升位置的RootID,包括子分类
		i=i+1
		if i>MoveNum then
			rsOrder("PrevID")=ID
			rsOrder.update
			conn.execute("Update NT_ClassName set RootID=RootID+1 where RootID=" & tRootID)
			conn.execute("Update NT_ClassName set NextID=" & rsOrder("ID") & " where ID=" & ID)
			exit do
		end if
		conn.execute("Update NT_ClassName set RootID=RootID+1 where RootID=" & tRootID)
		rsOrder.movenext
	loop
	rsOrder.movenext
	if rsOrder.eof then
		conn.execute("Update NT_ClassName set PrevID=0 where ID=" & ID)
	else
		rsOrder("NextID")=ID
		rsOrder.update
		conn.execute("Update NT_ClassName set PrevID=" & rsOrder("ID") & " where ID=" & ID)
	end if	
	rsOrder.close
	set rsOrder=nothing
	
	'然后再将当前分类从最后移到相应位置,包括子分类
	conn.execute("Update NT_ClassName set RootID=" & tRootID & " where RootID=" & MaxRootID)
end sub

sub DownOrder()
	dim ID,sqlOrder,rsOrder,MoveNum,cRootID,tRootID,i,rs,PrevID,NextID
	ID=trim(request("ID"))
	cRootID=Trim(request("cRootID"))
	MoveNum=trim(request("MoveNum"))
	if ID="" then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>参数不足!</li>"
	else
		ID=CLng(ID)
	end if
	if cRootID="" then
		FoundErr=true
		ErrMsg=ErrMsg & "<br><li>错误参数!</li>"
	else
		cRootID=Cint(cRootID)
	end if
	if MoveNum="" then
		FoundErr=true
		ErrMsg=ErrMsg & "<br><li>错误参数!</li>"
	else
		MoveNum=Cint(MoveNum)
		if MoveNum=0 then
			FoundErr=True
			ErrMsg=ErrMsg & "<br><li>请选择要提升的数字!</li>"
		end if
	end if
	if FoundErr=True then
		exit sub
	end if

	'得到本分类的PrevID,NextID
	set rs=conn.execute("select PrevID,NextID From NT_ClassName where ID=" & ID)
	PrevID=rs(0)
	NextID=rs(1)
	rs.close
	set rs=nothing
	'先修改上一分类的NextID和下一分类的PrevID
	if PrevID>0 then
		conn.execute "Update NT_ClassName set NextID=" & NextID & " where ID=" & PrevID
	end if
	if NextID>0 then
		conn.execute "Update NT_ClassName set PrevID=" & PrevID & " where ID=" & NextID
	end if

	dim mrs,MaxRootID
	set mrs=conn.execute("select max(rootid) From NT_ClassName")
	MaxRootID=mrs(0)+1
	'先将当前分类移至最后,包括子分类
	conn.execute("Update NT_ClassName set RootID=" & MaxRootID & " where RootID=" & cRootID)
	
	'然后将位于当前分类以下的分类的RootID依次减一,范围为要下降的数字
	sqlOrder="select * From NT_ClassName where ParentID=0 and RootID>" & cRootID & " order by RootID"
	set rsOrder=server.CreateObject("adodb.recordset")
	rsOrder.open sqlOrder,conn,1,3
	if rsOrder.bof and rsOrder.eof then
		exit sub        '如果当前分类已经在最下面,则无需移动
	end if
	i=1
	do while not rsOrder.eof
		tRootID=rsOrder("RootID")       '得到要提升位置的RootID,包括子分类
		i=i+1
		if i>MoveNum then
			rsOrder("NextID")=ID
			rsOrder.update
			conn.execute("Update NT_ClassName set RootID=RootID-1 where RootID=" & tRootID)
			conn.execute("Update NT_ClassName set PrevID=" & rsOrder("ID") & " where ID=" & ID)
			exit do
		end if
		conn.execute("Update NT_ClassName set RootID=RootID-1 where RootID=" & tRootID)
		rsOrder.movenext
	loop
	rsOrder.movenext
	if rsOrder.eof then
		conn.execute("Update NT_ClassName set NextID=0 where ID=" & ID)
	else
		rsOrder("PrevID")=ID
		rsOrder.update
		conn.execute("Update NT_ClassName set NextID=" & rsOrder("ID") & " where ID=" & ID)
	end if	
	rsOrder.close
	set rsOrder=nothing
	
	'然后再将当前分类从最后移到相应位置,包括子分类
	conn.execute("Update NT_ClassName set RootID=" & tRootID & " where RootID=" & MaxRootID)
end sub
%>
<html>
<head>
<title>一级分类重新排序</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<%
Behind.WriteHtmlHead
Title="一 级 分 类 排 序"
Link="<a href='Admin_Class.asp' class='black'>管理分类</a> | <a href='Admin_ClassAdd.asp' class='black'>添加分类</a> | <a href='Admin_ClassOrderN.asp' class='black'>N级分类排序</a>"
Behind.WriteHtmlTop Title,Link

dim Action
Action=trim(request("Action")) 
if Action="UpOrder" then 
	call UpOrder() 
elseif Action="DownOrder" then 
	call DownOrder() 
end if 
if FoundErr=True then 
	Behind.WriteErrMsg(ErrMsg)
	Set Netout = Nothing
else 
	call main() 
end if 
 
sub main() 
	dim sqlClass,rsClass,i,iCount,j 
	sqlClass="select * From NT_ClassName where ParentID=0 order by RootID" 
	set rsClass=server.CreateObject("adodb.recordset") 
	rsClass.open sqlClass,conn,1,1 
	iCount=rsClass.recordcount 
%> 
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" class="border"> 
  <tr class="title">  
    <td colspan="4" align="center" class="tdbg1"><strong>一级分类重新排序</strong></td> 
  </tr> 
  <% 
j=1 
do while not rsClass.eof 
%> 
    <tr class="tdbg" onMouseOut="this.style.backgroundColor=''" onMouseOver="this.style.backgroundColor='#EBEBEB'">  
      <td width="200">&nbsp;<%=rsClass("ClassName")%></td> 
<% 
	if j>1 then 
  		response.write "<form action='Admin_ClassOrder.asp?Action=UpOrder' method='post'><td width='150'>" 
		response.write "<select name=MoveNum size=1><option value=0>向上移动</option>" 
		for i=1 to j-1 
			response.write "<option value="&i&">"&i&"</option>" 
		next 
		response.write "</select>" 
		response.write "<input type=hidden name=ID value="&rsClass("ID")&">"
		response.write "<input type=hidden name=cRootID value="&rsClass("RootID")&">&nbsp;<input type=submit name=Submit value=修改>" 
		response.write "</td></form>" 
	else 
		response.write "<td width='150'>&nbsp;</td>" 
	end if 
	if iCount>j then 
  		response.write "<form action='Admin_ClassOrder.asp?Action=DownOrder' method='post'><td width='150'>" 
		response.write "<select name=MoveNum size=1><option value=0>向下移动</option>" 
		for i=1 to iCount-j 
			response.write "<option value="&i&">"&i&"</option>" 
		next 
		response.write "</select>" 
		response.write "<input type=hidden name=ID value="&rsClass("ID")&">"
		response.write "<input type=hidden name=cRootID value="&rsClass("RootID")&">&nbsp;<input type=submit name=Submit value=修改>" 
		response.write "</td></form>" 
	else 
		response.write "<td width='150'>&nbsp;</td>" 
	end if 
%> 
      <td>&nbsp;</td>
	</tr> 
  <% 
	j=j+1 
	rsClass.movenext 
loop 
%> 
</table> 
<% 
Behind.WriteHtmlEnd
rsClass.close 
set rsClass=nothing 
end sub 
%>